const http = require("http");
const url = require("url");
const moduleRouter = require("./module/moduleRouter.js");

http.createServer(function (req, res) {
    res.writeHead(200, {"Content-Type": "text/html;charset=utf-8"});
    let pathName = url.parse(req.url).pathname.replace("/", "");
    if (pathName === "") {
        pathName = "home";
    }
    try {
        if (pathName !== "favicon.ico") {
            moduleRouter[pathName](req, res);
        }
    } catch (e) {
        res.end("404 页面不存在！");
    }
}).listen(8080);